package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CaseMemberApiService;
import com.yixun.qfbao.apidto.UpdateCaseMemberReqDto;
import com.yixun.qfbao.apidto.UpdateCaseMemberResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.UpdateCaseMemberReqVo;
import com.yixun.qfbao.xf.model.dto.CaseMemberDto;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import com.yixun.qfbao.xf.service.CaseMemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("updateCaseMemberHander")
public class UpdateCaseMemberHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(UpdateCaseMemberHander.class);
    @Autowired
    private CaseMemberService caseMemberService;
    @Autowired
    private CaseMemberApiService caseMemberApiService;

    @SuppressWarnings("rawtypes")
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        UpdateCaseMemberReqVo reqVo = (UpdateCaseMemberReqVo)reqDto;
        UpdateCaseMemberReqDto reqDto1 = reqVo.getParams();
        BaseResponseDTO<UpdateCaseMemberResDto> res = new BaseResponseDTO<UpdateCaseMemberResDto>();
        UpdateCaseMemberResDto resDto = new UpdateCaseMemberResDto();
        try{
            CaseMemberDto caseMember = new CaseMemberDto();

            if(reqDto1.getSmsStatus() != null){
                caseMember.setId(reqDto1.getCaseMemberId());
                caseMember.setSmsStatus(reqDto1.getSmsStatus());
                caseMemberService.update(caseMember);
            }else if(reqDto1.getPhoneStatus() != null){
                caseMemberApiService.setCaseHotline(reqDto1.getPremisesId(),reqDto1.getCaseMemberId());
            }else if(reqDto1.getWxMsgStatus() != null){
                caseMember.setId(reqDto1.getCaseMemberId());
                caseMember.setWxMsgStatus(reqDto1.getWxMsgStatus());
                caseMemberService.update(caseMember);
            }

            resDto.setResult(ResultEnum.SUCCESS.getNo());
        }catch (Exception e){
            logger.error("updateCaseMemberHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
        }
        res.setResult(resDto.getResult());
        return res;
    }
}
